home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / HyperCuber 2.0 Source / CKeyControlsDirector.cp < prev    next >
Encoding:
Text File  |  1994-04-06  |  5.0 KB  |  196 lines  |  [TEXT/KAHL]

  1. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2. //| CKeyControlsDirector.cp
  3. //|
  4. //| This implements the controls dialog director
  5. //|_________________________________________________________
  6.  
  7. #include "CEditKeyControlsDirector.h"
  8. #include "CHyperCuberPrefs.h"
  9. #include "CKeyControlsArrayPane.h"
  10. #include "CKeyControlsDialog.h"
  11. #include "CKeyControlsDirector.h"
  12.  
  13. #include "HyperCuber Commands.h"
  14. #include "Keys.h"
  15.  
  16. #include <CPopupMenu.h>
  17. #include <CStdPopupPane.h>
  18.  
  19. //============================ Globals ============================\\
  20.  
  21. extern CDesktop         *gDesktop;
  22. extern CHyperCuberPrefs *gPrefs;
  23.  
  24.  
  25.  
  26. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  27. // CKeyControlsDirector::IKeyControlsDirector
  28. //
  29. // Purpose: Initialize the controls dialog.
  30. //
  31. // Parameters: none
  32. //_________________________________________________________
  33.  
  34. void CKeyControlsDirector::IKeyControlsDirector (CDirectorOwner *aSupervisor)
  35. {
  36.  
  37. #define CONTROLS_DIALOG_ID    131
  38.  
  39.     CDialogDirector::IDialogDirector (aSupervisor);            //  Init superclass
  40.  
  41.     array = new(CArray);                                    //  Set up the array
  42.     array->IArray(sizeof(key_control_struct));
  43.  
  44.     array_pane = new (CKeyControlsArrayPane);                //  Create the array pane
  45.  
  46.     BuildArrayFromPrefs();                                    //  Build the array
  47.  
  48.     CKeyControlsDialog *dialog = new (CKeyControlsDialog);    //  Set up the key controls dialog
  49.     dialog->IKeyControlsDialog(CONTROLS_DIALOG_ID, gDesktop,
  50.                                     this, array, array_pane);
  51.     itsWindow = dialog;
  52.  
  53. }    //=== CKeyControlsDirector::IKeyControlsDirector() ===\\
  54.  
  55.  
  56.  
  57. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  58. //| CKeyControlsDirector::BuildArrayFromPrefs
  59. //|
  60. //| Purpose: These procedure builds the array from the preferences.
  61. //|
  62. //| Parameters: none
  63. //|______________________________________________________________________________
  64.  
  65. void    CKeyControlsDirector::BuildArrayFromPrefs(void)
  66. {
  67.  
  68.     while(array->GetNumItems())                                //  Clear array
  69.         array->DeleteItem(1);
  70.  
  71.     long i;
  72.     for (i = 0; i < gPrefs->prefs.num_key_controls; i++)
  73.         array->InsertAtIndex(
  74.                 &(gPrefs->prefs.key_controls[i]), 10000);    //  Add this key control to array
  75.  
  76. }    //==== CMouseControlsDirector::BuildArrayFromPrefs() ====\\
  77.  
  78.  
  79.  
  80. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  81. //| CKeyControlsDirector::DoCommand
  82. //|
  83. //| Purpose: Handle commands for the dialog.
  84. //|
  85. //| Parameters: none
  86. //|_________________________________________________________
  87.  
  88. void CKeyControlsDirector::DoCommand( long aCmd)
  89. {
  90.  
  91.     Cell                cell;
  92.     key_control_struct    key_control;
  93.     Boolean                selection;
  94.  
  95.     switch (aCmd)
  96.     {
  97.         
  98.         case cmdDefaults:
  99.         
  100.             PrefsStruct prefs = gPrefs->prefs;        //  Save the current prefs
  101.             gPrefs->SetDefaults();                    //  Set all preferences to default values
  102.  
  103.             BuildArrayFromPrefs();                    //  Rebuild the array with default values
  104.             
  105.             gPrefs->prefs = prefs;                    //  Restore the current prefs
  106.             break;
  107.     
  108.         case cmdEdit:
  109.         
  110.             cell.h = cell.v = 0;
  111.             selection = array_pane->GetSelect(TRUE, &cell);        //  Find highlighted cell, if any
  112.             if (!selection) break;                                //  Don't do anything if no selection
  113.             array->GetItem(&key_control, cell.v + 1);                    //  Get the cell
  114.         
  115.             CEditKeyControlsDirector *ekcdialog_director = new (CEditKeyControlsDirector);
  116.             ekcdialog_director->IEditKeyControlsDirector(this, &key_control);
  117.             ekcdialog_director->TalkToUser();
  118.             ekcdialog_director->Dispose();
  119.  
  120.             array->SetItem(&key_control, cell.v + 1);                    //  Change the cell
  121.             
  122.             break;
  123.         
  124.         case cmdAdd:
  125.  
  126.             cell.h = cell.v = 0;
  127.             selection = array_pane->GetSelect(TRUE, &cell);        //  Find highlighted cell, if any
  128.             
  129.             key_control.dimension = 3;                                    //  Create a new key control
  130.             key_control.angle = 1;
  131.             key_control.increment = 1;
  132.             key_control.key_code = 0x31;
  133.             key_control.modifiers = 0;
  134.             
  135.             array->InsertAtIndex(&key_control, (selection) ?
  136.                             cell.v + 1 : 10000);                //  Insert a new cell before
  137.                                                                 //   selection or at end if none.
  138.             break;
  139.  
  140.         case cmdRemove:
  141.         
  142.             cell.h = cell.v = 0;
  143.             selection = array_pane->GetSelect(TRUE, &cell);        //  Find highlighted cell, if any
  144.             
  145.             if (selection)
  146.                 array->DeleteItem(cell.v + 1);                    //  Remove the cell
  147.  
  148.             break;
  149.         
  150.         default:
  151.             inherited::DoCommand( aCmd);
  152.             break;
  153.     }
  154.     
  155. }    //=== CKeyControlsDirector::DoCommand ===\\
  156.  
  157.  
  158.  
  159. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  160. // CKeyControlsDirector::TalkToUser
  161. //
  162. // Purpose: Handle commands for the dialog.
  163. //
  164. // Parameters: none
  165. //_________________________________________________________
  166.  
  167. void CKeyControlsDirector::TalkToUser(void)
  168. {
  169.  
  170.     long dismiss_command;
  171.     
  172.     BeginModalDialog();
  173.     long dismiss = DoModalDialog(cmdOK);
  174.     
  175.     if (dismiss == cmdOK)
  176.         {
  177.  
  178.         gPrefs->Lock(TRUE);
  179.         PrefsStruct *prefs = &(gPrefs->prefs);                    //  Get pointer to the current prefs
  180.         prefs->num_key_controls = array->GetNumItems();
  181.  
  182.         long i;
  183.         for (i = 0; i < prefs->num_key_controls; i++)
  184.             {
  185.             key_control_struct key_control;
  186.         
  187.             array->GetItem(&key_control, i + 1);                //  Get the key control
  188.             prefs->key_controls[i] = key_control;                //  Move this key control to prefs
  189.             }
  190.  
  191.         gPrefs->Lock(FALSE);
  192.         
  193.         }
  194.     
  195. }    //=== CKeyControlsDirector::TalkToUser ===\\
  196.